package com.aurora.oa.home.presenter;


import com.aurora.oa.Constants.AuroraConstants;
import com.aurora.oa.bean.HttpResult;
import com.aurora.oa.home.model.HomePageData;
import com.aurora.oa.home.view.HomeFragmentView;
import com.aurora.oa.listener.OnRequestHttpDataListener;
import com.aurora.oa.model.RequestHttpModel;
import com.aurora.oa.model.RequestHttpModelImpl;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;

/**
* Created by Administrator on 2017/03/13
*/

public class HomeFragmentPresenterImpl implements HomeFragmentPresenter{

    HomeFragmentView homeFragmentView;
    RequestHttpModel requestHttpModel;
    public HomeFragmentPresenterImpl(HomeFragmentView homeFragmentView) {
        this.homeFragmentView = homeFragmentView;
        requestHttpModel = new RequestHttpModelImpl();
    }

    @Override
    public void refreshHomeFragment() {

        requestHttpModel.requestHttpDataString(AuroraConstants.GET_SHOUYE_URL,new OnRequestHttpDataListener(){

            @Override
            public void onRequestDataSuccess(String body) {
                Gson gson = new Gson();
                Type type = new TypeToken<HomePageData>() {
                }.getType();
                HomePageData result = gson.fromJson(body, type);
                homeFragmentView.refreshHomePage(result);
            }

            @Override
            public void onRequestDataFail(String message) {

            }
        });

    }
}